package com.atguigu.srb.core.controller.api;


import com.atguigu.common.result.R;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Dragon
 * @since 2021-07-29
 */
@Api(tags = "借款平台")
@Slf4j
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {

    @Resource
    private BorrowerService borrowerService;
    @ApiOperation("保存借款人信息")
    @PostMapping("/auth/save")
    public R borrorAccount(@RequestBody BorrowerVO borrowerVO, HttpServletRequest request){
        //从网络请求里的Token里面拿取用户ID
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);

         borrowerService.saveUserAccount(borrowerVO,userId);
       return R.ok().message("保存成功");
    }

    @ApiOperation("获取借款人认证状态")
    @GetMapping("/auth/getBorrowerStatus")
    public R getBorrowerStatus(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
       Integer integer =    borrowerService.getStatusByUserId(userId);
       return R.ok().data("borrowerStatus",integer);
      }



}

